<?php
error_reporting(7);

if (empty($_GET[action]) AND empty($_POST[action])) {
	$_GET[action] = "edit";
}

if ($_GET[action]=="edit") {
	$template_name = "setting_edit.htm";
	require "common.php";
	# START 检查权限
	if (!$perm->check_permission(MISC, MISC_SETTINGS_EDIT)) {
		display_nopermission();
	}
	# END 检查权限
	$fp = fopen(INI_FILE,rb);
	$content = fread($fp,filesize(INI_FILE));
	fclose($fp);
	$tpl->assign("content", htmlspecialchars($content));
	$tpl->output();
	require "footer.php";
}

if ($_POST[action]=="update") {
	require "common.php";
	# START 检查权限
	if (!$perm->check_permission(MISC, MISC_SETTINGS_EDIT)) {
		display_nopermission();
	}
	# END 检查权限
	$content = $_POST[content];
	if (!my_isset($_POST[content])) {
		display_error("内容不能为空!");
	}
	$fp = fopen(INI_FILE,w);
	fwrite($fp,$content,strlen($content));
	fclose($fp);
	redirect("./setting.php?action=edit","更新成功！");
}

?>